//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace TridentProvenanceTray
{
    using System;
    using System.Globalization;
    using System.Windows;
    using Microsoft.Win32;
    using Microsoft.Research.ScientificWorkflow.TridentUtilities;

    /// <summary>
    /// Interaction logic for TrayWindow.xaml
    /// </summary>
    public sealed partial class AboutBox : Window
    {
        /// <summary>
        /// Initializes a new instance of the AboutBox class
        /// </summary>
        public AboutBox()
        {
            InitializeComponent();
            this.GetBuildNumberFromRegistry();
        }

        /// <summary>
        /// Retrieves the current build number from windows registry.
        /// </summary>
        /// <returns>Build Number</returns>
        private void GetBuildNumberFromRegistry()
        {
            try
            {
                string builNumber = "Version";
                RegistryKey regKey = Registry.CurrentUser.OpenSubKey(Constants.PRODUCT_VERSION_REGISTRY_PATH);
                if (null != regKey)
                {
                    this.tbkVersion.Text = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", builNumber, regKey.GetValue(Constants.PRODUCT_VERSION_REGISTRY_KEY).ToString());
                }
            }
            catch (Exception exception)
            {
                TridentErrorHandler.HandleUIException(exception);
            }
        }
    }
}
